﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:System="clr-namespace:System;assembly=mscorlib"
                    xmlns:Classes="clr-namespace:SqliteHelper.Classes">
   
   <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="/SqliteHelper;component/Resources/Common.xaml" />
   </ResourceDictionary.MergedDictionaries>
   
   <ObjectDataProvider x:Key="sqliteColumnTypes"
                       ObjectType="{x:Type System:Enum}"
                       MethodName="GetValues">
      <ObjectDataProvider.MethodParameters>
         <x:Type TypeName="Classes:SqliteColumnType" />
      </ObjectDataProvider.MethodParameters>
   </ObjectDataProvider>

   <DataTemplate DataType="{x:Type Classes:SqliteTableViewModel}">
      <Grid>
         <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
         </Grid.RowDefinitions>
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
         </Grid.ColumnDefinitions>
         
         <TextBlock Text="Table Name:"
                    Grid.Row="0"
                    Grid.Column="0"
                    Margin="0,0,5,0" />
         
         <TextBox Grid.Row="0"
                  IsReadOnly="{Binding Path=IsNameReadOnly}"
                  Grid.Column="1">
            <TextBox.Text>
               <Binding Path="Name"
                        UpdateSourceTrigger="PropertyChanged">
                  <Binding.ValidationRules>
                     <Classes:TableNameValidationRule />
                  </Binding.ValidationRules>
               </Binding>
            </TextBox.Text>
         </TextBox>
         
         <DataGrid AutoGenerateColumns="False"
                   Grid.Row="1"
                   RowHeaderWidth="20"
                   Grid.Column="0"
                   Grid.ColumnSpan="2"
                   Margin="0,10,0,0"
                   ItemsSource="{Binding Path=Columns}">
            
            <DataGrid.RowValidationRules>
               
            </DataGrid.RowValidationRules>
            
            <DataGrid.Columns>
               <DataGridTextColumn Binding="{Binding Path=Name}"
                                   Header="Column Name"
                                   Width="*"/>
               <DataGridComboBoxColumn Header="Data Type"
                                       Width="100"
                                       ItemsSource="{Binding Source={StaticResource sqliteColumnTypes}}"
                                       SelectedItemBinding="{Binding Path=DataType}"/>
            </DataGrid.Columns>
         </DataGrid>
      </Grid>
   </DataTemplate>
    
</ResourceDictionary>